package com.xggstudio.crm.ui.mvp.v;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.xggstudio.crm.R;
import com.xggstudio.crm.base.BaseFragment;
import com.xggstudio.crm.ui.mvp.m.ReturnVisitBean;
import com.xggstudio.crm.ui.mvp.p.P_callBack;
import com.xggstudio.crm.ui.mvp.v.adapter.BaseCommonAdapter;
import com.xggstudio.crm.ui.mvp.v.adapter.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class CallBackFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener,ICallBack {

    private SwipeRefreshLayout refreshLayout;

    private RecyclerView list;

    private BaseCommonAdapter adapter;

    private P_callBack callBack;

    @Override
    protected int getLayout() {
        return R.layout.fragment_callback;
    }

    @Override
    protected void init(View v) {

        refreshLayout = (SwipeRefreshLayout) $(R.id.refresh);
        list = (RecyclerView) $(R.id.list);

        refreshLayout.setOnRefreshListener(this);

        initList();

        callBack = new P_callBack(this);
        callBack.getdata(1,10);
    }

    private void initList(){

        List<ReturnVisitBean.ResultBean> data = new ArrayList<>();


        adapter = new BaseCommonAdapter<ReturnVisitBean.ResultBean>(getContext(),R.layout.item_callback,data) {

            @Override
            public void convert(ViewHolder holder, ReturnVisitBean.ResultBean bean, int position) {

                holder.setText(R.id.name,bean.getClient_name());
                holder.setText(R.id.phone,bean.getClient_phone());
                holder.setText(R.id.datatime,bean.getCreated_at());
                holder.setText(R.id.content,bean.getUser_name());


            }
        };

        list.setLayoutManager(new LinearLayoutManager(getActivity()));
        list.setAdapter(adapter);

    }

    @Override
    public void onRefresh() {
        refreshLayout.setRefreshing(false);
    }

    @Override
    public void showData(ReturnVisitBean returnVisitBean) {

        adapter.addDatas(returnVisitBean.getResult());

    }

    @Override
    public void showError(String msg) {

    }

    @Override
    public void noNet() {

    }
}
